package com.kaifamiao.queue;

import java.util.Deque;
import java.util.LinkedList;

/**
 * 用双端队列可以模拟堆栈操作
 *  void push( E e )
 *  E peek()
 *  E pop()
 */
public class DequeTest3 {

    public static void main(String[] args) {

        Deque<String> s = new LinkedList<>();
        s.push( "孙悟空" );
        s.push( "孙行者" );
        System.out.println( s );

        s.push( "者行孙" );
        System.out.println( s );

        String top = s.peek();
        System.out.println( top );
        System.out.println( s );

        top = s.pop();
        System.out.println( top );
        System.out.println( s );

        System.out.println( s.pop() );
        System.out.println( s );

        System.out.println( s.pop() );
        System.out.println( s );

        System.out.println( s.peek() );
        // System.out.println( s.pop() ); // NoSuchElementException
    }

}
